<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<div id="box"></div>
<body>
    <script type="text/javascript">
        // 字符串的批量替换
        var info = '<div>hello {{ uname }}，你多大了？ 我{{age}}岁了</div>'
        var user = {
            uname: 'cc',
            age: 28
        }
        // 小括号包裹的称之为子串
        var pattern = /{{\s*([a-zA-Z]+)\s*}}/
        var ret = pattern.exec(info)
        var key = ret[0] // {{ uname }}
        var val = user[ret[1]] 
        var result1 = info.replace(key, val)
        console.log(result1)

        var ret2 = pattern.exec(result1)
        var result2 = result1.replace(ret2[0], user[ret2[1]])
        console.log(result2)
        var divs = document.getElementById("box")
         divs.innerHTML = result2
    </script>
</body>

</html>